/* debug_usb.c -- serial output via a usb debug path and the ad command
**
** Copyright 2006, Brian Swetland.  All rights reserved.
** See provided LICENSE file or http://frotz.net/LICENSE for details.
*/

#include "../tools/protocol.h"

#define MAX_DATA 128

#define DEBUG_BRIDGE ((debug_bridge*) DEBUG_BRIDGE_ADDR)

void ser_init(void)
{
    debug_bridge *db = DEBUG_BRIDGE;

    db->handshake = 0;
    db->count = 0;
}

void ser_putc(unsigned n)
{
    debug_bridge *db = DEBUG_BRIDGE;

    while(db->handshake != 0) ;

    db->data[db->count++] = n;
    if((db->count == DEBUG_MAX_DATA) || (n == '\n')) {
        db->handshake = DEBUG_HANDSHAKE;
    }
}

void ser_puts(char *s)
{
    while(*s) ser_putc(*s++);
}
